/**
 * Created by hdr on 17/8/17.
 */
import HeightReport from './Height'
import WeightReport from './Weight'
import BMIReport from './BMI'
import BodyfatReport from './Bodyfat'
import WaterReport from './Water'
import MuscleReport from './Muscle'
import MuscleMassReport from './MuscleMass'
import BoneReport from './Bone'
import LbmReport from './Lbm'
import ProteinReport from './Protein'
import SubfatReport from './Subfat'
import VisfatReport from './Visfat'
import BodyAgeReport from './BodyAge'
import BodyShapeReport from './BodyShape'
import BmrReport from './Bmr'
import HeartRateReport from './HeartRate'
import HeartIndexReport from './HeartIndex'
//import BasalMetabolicReport from './BasalMetabolic'
import BestVisualWeightReport from './BestVisualWeight'
import FatControlReport from './FatControl'
import MineralSaltReport from './MineralSalt'
import MuscleRateReport from './MuscleRate'
import MuscleControlReport from './MuscleControl'
import StandWeightReport from './StandWeight'
import WaterContentReport from './WaterContent'
import WeightControlReport from './WeightControl'
import ObesityDegreeReport from './ObesityDegree'
import ProteinMassReport from './ProteinMass'
import BFWReport from './BFW'

const { dataValid} = require('../utils/util.js');

class Report {

  reportItemList = [];

  constructor(measure) {
    this.measure = measure;
    this._initReportItem()
  }

  get score() {
    return this.measure.score || 0
  }

  get measureTime() {
    return this.measure.time
  }

  isValid () {
    return dataValid(this.measure);
  }
  _initReportItem() {
    const arr = [];
    const weightReports = [
      WeightReport,
      HeightReport,
      BMIReport
    ];
    const reports = [
      HeartRateReport,
      HeartIndexReport,
      BodyfatReport,
      WaterReport,
      MuscleReport,
      MuscleMassReport,
      BoneReport,
      LbmReport,
      ProteinReport,
      SubfatReport,
      VisfatReport,
      BodyAgeReport,
      BodyShapeReport,
      BmrReport,
      //BasalMetabolicReport,
      BestVisualWeightReport,
      FatControlReport,
      MineralSaltReport,
      MuscleRateReport,
      MuscleControlReport,
      StandWeightReport,
      WaterContentReport,
      WeightControlReport,
      ObesityDegreeReport,
      ProteinMassReport,
      BFWReport,
    ];
    var addReport = (report) => {
      if (report.isEnable(this.measure)) {
        const item = report.build(this.measure);
        // console.log("数据：", item)
        if (item) {
          if (item.fixLevel > 0 && item.value.toFixed) {
            item.value = parseFloat(item.value.toFixed(item.fixLevel));
            if (item.offset !== 0) {
              item.offset = parseFloat(item.offset.toFixed(item.fixLevel))
            }
            if (item.boundaries && item.boundaries.length > 0)
              item.boundaries = item.boundaries.map(value => parseFloat(value.toFixed(item.fixLevel)))
          }
          if (item.showBar) {
            if (item.min > item.value) {
              item.min = item.value
            }
            if (item.max < item.value) {
              item.max = item.value
            }
          }
          this.reportItemList.push(item)
        }
      }
    };
    weightReports.forEach(addReport);
    // 分数为0时只显示体重与BIM
    if (this.score > 0) {
      reports.forEach(addReport)
    }
    // console.log(this.reportItemList, this.score)
    // this.reportItemList
  }

}

export default Report



// WEBPACK FOOTER //
// ./src/report/Report.js
